package com.liveneo.adapter.mobile.service.impl;

import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.liveneo.adapter.base.entity.PrpmOcrPayee;
import com.liveneo.adapter.base.mapper.PrpmOcrPayeeMapper;
import com.liveneo.adapter.base.support.BaseServiceImpl;
import com.liveneo.adapter.mobile.model.request.OcrPayeeInfoRequest;
import com.liveneo.adapter.mobile.service.MobileOcrPayeeService;
import com.liveneo.adapter.mobile.util.UUIDUtils;

/**
 * 领款人信息服务类
 * @author zhaoyy
 * @date 2016-09-28
 */
@Service
public class MobileOcrPayeeServiceImpl extends BaseServiceImpl implements MobileOcrPayeeService {
    @Autowired
    private PrpmOcrPayeeMapper ocrPayeeMapper;

    @Override
    public synchronized PrpmOcrPayee getOcrPayeeByLossUuid(String lossUuid) {
        return ocrPayeeMapper.getOcrPayeeByLossUuid(lossUuid);
    }

    @Override
    public int saveOcrPayee(OcrPayeeInfoRequest request, int type) {
        PrpmOcrPayee ocrPayee = new PrpmOcrPayee();
        if (type == 1) { // 保存领款人身份证信息
            ocrPayee.setOcrPayeeId(UUIDUtils.getUUIDStr());
            ocrPayee.setSurveyUserCode(request.getUserCode());
            ocrPayee.setCaseInfoId(request.getCaseUuid());
            ocrPayee.setCaseNo(request.getCaseNo());
            // ocrPayee.setLossId(request.getLossId());
            ocrPayee.setLossItemId(request.getLossUuid());
            ocrPayee.setPayeeName(request.getPayeeName());
            ocrPayee.setPayeeCard(request.getPayeeCard());
            ocrPayee.setInsuredPhone(request.getInsuredPhone());
            ocrPayee.setValidCardDate(request.getValidCardDate());
            ocrPayee.setCreateBy(request.getUserCode());
            ocrPayee.setCreateTime(new Date());
            ocrPayee.setModifyBy(request.getUserCode());
            ocrPayee.setModifyTime(new Date());
        } else { // 保存领款人银行卡信息
            ocrPayee.setOcrPayeeId(UUIDUtils.getUUIDStr());
            ocrPayee.setSurveyUserCode(request.getUserCode());
            ocrPayee.setCaseInfoId(request.getCaseUuid());
            ocrPayee.setCaseNo(request.getCaseNo());
            // ocrPayee.setLossId(request.getLossId());
            ocrPayee.setLossItemId(request.getLossUuid());
            ocrPayee.setBank(request.getBank());
            ocrPayee.setBankCode(request.getBankCode());
            ocrPayee.setBranchBank(request.getBranchBank());
            ocrPayee.setBranchBankCode(request.getBranchBankCode());
            ocrPayee.setBankCard(request.getBankCard());
            ocrPayee.setCardType(request.getCardType());
            ocrPayee.setProvince(request.getProvince());
            ocrPayee.setProvinceCode(request.getProvinceCode());
            ocrPayee.setCity(request.getCity());
            ocrPayee.setCityCode(request.getCityCode());
            // ocrPayee.setInfoSources(request.getInfoSources());
            ocrPayee.setCreateBy(request.getUserCode());
            ocrPayee.setCreateTime(new Date());
            ocrPayee.setModifyBy(request.getUserCode());
            ocrPayee.setModifyTime(new Date());
        }
        return ocrPayeeMapper.insertSelective(ocrPayee);
    }

    @Override
    public int updateOcrPayee(PrpmOcrPayee ocrPayee, OcrPayeeInfoRequest request, int type) {
        if (type == 1) { // 更新领款人身份证信息
            ocrPayee.setPayeeName(request.getPayeeName());
            ocrPayee.setPayeeCard(request.getPayeeCard());
            ocrPayee.setInsuredPhone(request.getInsuredPhone());
            ocrPayee.setValidCardDate(request.getValidCardDate());
            ocrPayee.setModifyBy(request.getUserCode());
            ocrPayee.setModifyTime(new Date());
        } else { // 更新领款人银行卡信息
            ocrPayee.setBank(request.getBank());
            ocrPayee.setBankCode(request.getBankCode());
            ocrPayee.setBranchBank(request.getBranchBank());
            ocrPayee.setBranchBankCode(request.getBranchBankCode());
            ocrPayee.setBankCard(request.getBankCard());
            ocrPayee.setCardType(request.getCardType());
            ocrPayee.setProvince(request.getProvince());
            ocrPayee.setProvinceCode(request.getProvinceCode());
            ocrPayee.setCity(request.getCity());
            ocrPayee.setCityCode(request.getCityCode());
            // ocrPayee.setInfoSources(request.getInfoSources());
            ocrPayee.setModifyBy(request.getUserCode());
            ocrPayee.setModifyTime(new Date());
        }
        return ocrPayeeMapper.updateByPrimaryKeySelective(ocrPayee);
    }

    @Override
    public PrpmOcrPayee selectPayeeByCaseNo(PrpmOcrPayee params) {
        return ocrPayeeMapper.selectPayeeByCaseNo(params);
    }
}
